﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SmartMD.DataAccess.Interface.Dao;
using SmartMD.DataModel.Entity;
using System.Data;

namespace SmartMD.DataAccess.Oracle.DaoImpl
{
    public class SysInfoDao : BaseGenericDaoImpl, IBaseGenericDao
    {
        public bool SaveOrUpdateObject(Object entity)
        {
            SysInfoEntity sysInfo = (SysInfoEntity)entity;
            StringBuilder sb = new StringBuilder();
            sb.Append(" insert into");
            sb.Append(" DUO_SYSTEM_ENVIRONMENT (ID, NAME, VALUE, DESCRIPTION)");
            sb.Append(" values(");
            sb.Append(" '" + sysInfo.Id + "',");
            sb.Append(" '" + sysInfo.Name + "',");
            sb.Append(" '" + sysInfo.Value + "',");
            sb.Append(" '" + sysInfo.Description + "'");
            sb.Append(")");
            bool success = this.dbConn.Insert(sb.ToString());
            return success;
        }
        public bool DeleteObject(Object entity)
        {
            return false;
        }
        public SysInfoEntity GetObjectById(string name)
        {
            SysInfoEntity sysInfo = new SysInfoEntity();
            StringBuilder sb = new StringBuilder();
            sb.Clear();
            sb.Append(" select *");
            sb.Append(" from DUO_SYSTEM_ENVIRONMENT");
            sb.Append(" where NAME='" + name + "'");

            DataTable dt = this.dbConn.Select(sb.ToString());
            if (dt != null && dt.Rows.Count > 0)
            {
                for (int j = 0; j < dt.Rows.Count; j++)
                {
                    for (int i = 0; i < dt.Columns.Count; i++)
                    {
                        string clmName;
                        clmName = dt.Columns[i].ColumnName;
                        sysInfo.setValue(clmName, dt.Rows[j][clmName]);
                    }
                }
                return sysInfo;
            }
            return null;
        }
    }
   
}
